<?php
namespace Common\Model;
use Common\Model\BaseModel;
class CheckModel extends BaseModel
{
    protected $tableName = 'check';
    public function addCheck($post)
    {

        $ret = array('status'=>'','info'=>'');
        $data = $this->returnData($post);
        if($this->create($data))
        {
            $res = null !== $data['id'] ? $this->save($data) : $this->add($data);
            if(false !== $res)
            {
                $ret['status'] = true;
                $ret['info']   = "Success";
            }
            else
            {
                $ret['status'] = false;
                $ret['info']   = $this->getDbError();
            }
        }
        else
        {
                $ret['status'] = false;
                $ret['info']   = $this->getError();
        }
    
        return $ret;
    }
    public function returnData($post)
    {

        $return['id']             = !empty($post['id']) ? intval($post['id']) : null;
        $return['tab_check_id']   = !empty($post['tab_check_id']) ? addslashes($post['tab_check_id']) : $this->createTabCheckid();
        $return['room_id']        = !empty($post['room_id']) ? intval($post['room_id']) :0 ;
        $return['check_content']  = !empty($post['check_content']) ? addslashes($post['check_content']) : '';
        $return['check_time']     = !empty($post['check_time']) ? strtotime($post['check_time']) : time();
        $return['status']         = !empty($post['status']) ? intval($post['status']) : 3;
        $return['remark']         = !empty($post['remark']) ? addslashes($post['remark']) : '';
        $return['read']           = !empty($post['read']) ? intval($post['read']) : 2;
        $return['is_check']       = !empty($post['is_check']) ? intval($post['is_check']) : 3;

        return $return;  
    }

    public function createTabCheckid()
    {

        $tab_check_id = date('YmdHis',time());
        return $tab_check_id;
    }

    public function getList()   //暂时没用到
    {
      $list = $this->select();
      return $list;
    }
    public function judge($id,$status,$remark='')
    {
        if($this->role_id == self::ROLE_TEACHER){
            $save = array('id' =>$id, 'is_check' => $status, 'remark' => $remark);
        }else if($this->role_id == self::ROLE_TEACHER_MGR){
            $save = array('id' =>$id, 'status' => $status, 'remark' => $remark);
        }else if($this->role_id ==self::ROLE_BAOWEICHU){
            $save = array('id' =>$id, 'status' => $status,'is_check' => $status, 'remark' => $remark);
        }else{
           return false;
        }
        $res = $this->save($save);
        return $res;
    }
}